<template>
	<view class="container">
		<view class="top">
			<u--form :model="form" ref="uForm" :rules="rules">
				<view class="dqglyBox">
					<u-form-item label="技术人员:" labelWidth="160rpx" prop="zrrName" >
						<uni-combox v-model="form.zrrName" 
						:candidates="sblist" style="width: 100%;" 
						placeholder="请选择技术人员" emptyTips="无数据"
						></uni-combox>
					</u-form-item>
				</view>
			</u--form>
			<view class="btn">
				<u-button class="btn" type="primary" @click="submit(form)">转交</u-button>	
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
						glyNow: '',
						zrrName: '',
					},
				rules: {
							glyNow: [
						{
							required: true,
							message: '请输入',
							trigger: ['blur', 'change']
									}
							],zrrName: [
						{
							required: true,
							message: '请选择',
							trigger: ['blur', 'change']
									}
							],
				},
				options: ['Option 1', 'Option 2', 'Option 3'], // 下拉选项的数组
				myzpSz: {},
				sblist: [],// 默认选中的值
				sb:'',
				userInfo: {},
			}
		},
		onLoad(query) {
			console.log(query,'我来指派');
			// 从 query 中获取传递过来的数据，并将其转换为对象
			this.myzpSz = JSON.parse(query.myzpData || "{}");
			this.userInfo = uni.getStorageSync('userInfo')
			this.xz()
		},
		methods: {
			xz(){
				let GRP1 = {
						GRP1: [{
							// ID:this.userInfo.ID,//"1",
							// PHONE: this.myzpSz.PROPHONE,
					}] 
				}
				let GRP1Json = JSON.stringify(GRP1)
						uni.request({
						  url: 'http://125.64.76.148:8125/KXJDX3Api/x3api', // 替换为实际的接口URL
						  method: 'POST', 
						  data: {
							"username":"APIUSER",
							"passwd":"123",
							"publicName":"WSLISTYDUR",
							"method":"run",
							"test":uni.getStorageSync('test') ? "true" : "false",
							"inputXml":JSON.stringify(GRP1)
						  },
						  success: (res) => {
							let cxsbData = JSON.parse(res.data.message)
							for (var i = 0; i < cxsbData.GRP1.length; i++) {
								if(cxsbData.GRP1[i].Y2==2){
									this.sblist.push(''+cxsbData.GRP1[i].NAME+'-'+cxsbData.GRP1[i].PHONE)
								}
							}
						  },
						  fail: (err) => {
							// 请求失败的处理逻辑
							console.error(err);
						  }
						});
			},
			submit(q) {
				var sb = this.form.zrrName
				var sb2 = this.form.xzryName
				if(!this.sblist.find(item => item==sb)){
					uni.$u.toast('技术人员不正确')
					return
				}
				var name=sb.slice(0,sb.indexOf('-'))
				var phone=sb.slice(sb.indexOf('-')+1)
				console.log(name,phone)
				// return
				let GRP1 = {
						GRP1: [{
							YFLG: "1",//标识
							YDRNUM: this.myzpSz.YDRNUM,//单号
							SERPSON: name,//维修人
							SERPHONE: phone,//维修人电话
							YFLY: '转交',//附带语言
							YPDUSR: this.userInfo.NAME,
							YPDPHONE: this.userInfo.PHONE,
					}]   
				}
				let GRP1Json = JSON.stringify(GRP1)
				// console.log(GRP1Json,'55666667777888');
				uni.request({
				  url: 'http://125.64.76.148:8125/KXJDX3Api/x3api'+"?_t="+new Date().getTime(), // 替换为实际的接口URL
				  method: 'POST', 
				  data: {
					"username":"APIUSER",
					"passwd":"123",
					"publicName":"WSGENXDR",
					"method":"run",
					"test":uni.getStorageSync('test') ? "true" : "false",
					"inputXml":JSON.stringify(GRP1)
				  },
				  success: (res) => {
					  console.log(res.data.message,'shouliqueren');
					// 请求成功的处理逻辑
					if(res.data.status=="error"){
						alert(res.data.message);
						return false;
					}else{
						let resR = JSON.parse(res.data.message)
						// console.log(resR.GRP2,56777);
						if(resR.GRP1.WOK==0){
							// 显示创建成功的消息提示
							 uni.showToast({
							   title: '转交成功',
							   icon: 'success',
							   duration: 2000
							});
							this.form=''
							let that = this
							setTimeout(function() {
								uni.redirectTo({url:"/pages/mydzPages/mydzPages"})
							}, 2000);
						}else{
							uni.showToast({
							   title: '转交失败',
							   icon: 'error',
							   duration: 2000
							});
						}
					}
				  },
				  fail: (err) => {
					// 请求失败的处理逻辑
					console.error(err);
				  }
				});
			},
			//  onPickerChange(event) {
			//       this.selectedOption = this.options[event.detail.value]; // 更新选中的值
			// }
		}
	}
</script>

<style>
.container {
 height: 100vh;
  background-color: #f2f2f2 !important;
  overflow: hidden;
}
.top{
	margin-top: 20rpx;
	
}
.labelBox{
	display: flex;
	justify-content: space-between;
	padding-left: 20rpx;
	border-bottom: 1px solid #f1f1f1;
}
.fdyyBox{
	margin-top: 60rpx;
	background-color: white;
	padding-left: 20rpx;
}
.btn{
	width: 60%;
	margin: 30rpx auto;
	}
.dqglyBox{
	padding-left: 20rpx;
	margin-top: 70rpx;
	background-color: white;
}
/* 样式可以根据您的需求进行自定义 */
.picker {
  padding: 15rpx;
  border: 1px solid #ccc;
  border-radius: 5rpx;
  text-align: center;
}
</style>
